<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';

$config = [
    'id' => 'tools',
    'basePath' => dirname(__DIR__),
    'bootstrap' => [
        'log',
        // [//启动引导的响应格式
        //     'class'            => 'yii\filters\ContentNegotiator',
        //     'formats'          => [
        //         'application/json' => yii\web\Response::FORMAT_JSON,
        //         'application/xml'  => yii\web\Response::FORMAT_HTML,
        //     ],
        //     'languages'        => ['cn'],
        // ]
    ],
    'language' => 'zh-CN',
    'timeZone' => 'Asia/Shanghai',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    // 'defaultRoute' => 'index',
    'components' => [
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => 'fBxFtAKaCzGbPu7Auh4m59kVCNm3Ii6p',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        // 'errorHandler' => [
        //     'errorAction' => 'site/error',
        // ],
        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'enableStrictParsing' => false,
            'rules' => [
                'api/ucc/<action:\w+>' => 'api/ucc/query',
            ],
        ],
        'i18n' => [
            'translations' => [
                '*' => [
                    'class' => 'yii\i18n\PhpMessageSource',
                    'basePath' => '@app/messages',
                ],
            ],
        ],
    ],
    'modules' => [
        'api' => [
            'class' => 'app\modules\api\Module',
            // ... 模块其他配置 ...
        ],
    ],
    'params' => $params,
    'on beforeAction' => function ($event) {
        // var_dump($event);
        // die;
        // Yii::$app->response->format= yii\web\Response::FORMAT_JSON;
    }
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        //'allowedIPs' => ['127.0.0.1', '::1'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1'],
        'generators' => [
            'crud' => [ //生成器名称
                'class' => 'app\gii\generators\crud\Generator',
                'templates' => [ //设置我们自己的模板
                    //模板名 => 模板路径
                    'myCrud' => '@app/gii/generators/crud/default',
                ]
            ]
        ],
    ];
}

return $config;
